#include "ui_message.h"
#include "ui_std_ex.h"
#include <iostream>


namespace UI
{

UI_Message::UI_Message(const EMessageType MessageType, const UI_MessageClient* pDestination, const UI_MessageClient* pSource) :
	m_MessageType(MessageType),
	m_pDestination(pDestination),
	m_pSource(pSource)
{

}


UI_SDLMessage::UI_SDLMessage(const EMessageType MessageType, const UI_MessageClient* pDestination, const UI_MessageClient* pSource, SDL_Event SDLEvent) :
	UI_Message(MessageType, pDestination, pSource),
	SDLEvent(SDLEvent)
{

}


UI_KeyboardMessage::UI_KeyboardMessage(const EMessageType MessageType, const UI_MessageClient* pDestination, const UI_MessageClient* pSource,
		unsigned char ScanCode, SDLMod Modifiers, SDLKey Key, Uint16 Unicode) :
	UI_Message(MessageType, pDestination, pSource),
	ScanCode(ScanCode),
	Modifiers(Modifiers),
	Key(Key),
	Unicode(Unicode)
{

}


UI_MouseMessage::UI_MouseMessage(const EMessageType MessageType, const UI_MessageClient* pDestination, const UI_MessageClient* pSource,
		UI_Point Point, UI_Point Relative, unsigned int Button) :
	UI_Message(MessageType, pDestination, pSource),
	Point(Point),
	Relative(Relative),
	Button(Button)
{

}


unsigned int UI_MouseMessage::TranslateSDLButton(Uint8 SDLButton)
{
	unsigned int Button = 0;
	switch (SDLButton)
	{
	case SDL_BUTTON_LEFT:
		Button = LEFT;
		break;
	case SDL_BUTTON_RIGHT:
		Button = RIGHT;
		break;
	case SDL_BUTTON_MIDDLE:
		Button = MIDDLE;
		break;
	case SDL_BUTTON_WHEELUP:
		Button = WHEELUP;
		break;
	case SDL_BUTTON_WHEELDOWN:
		Button = WHEELDOWN;
		break;
	default:
		std::cerr<< "Untranslated SDL Button # " + stdex::itoa(SDLButton) << std::endl;
		break;
	}

	return Button;
}


unsigned int UI_MouseMessage::TranslateSDLButtonState(Uint8 SDLButtonState)
{
	unsigned int Button = 0;
	if (SDLButtonState & SDL_BUTTON(1))
	{
		Button |= LEFT;
	}
	if (SDLButtonState & SDL_BUTTON(2))
	{
		Button |= RIGHT;
	}
	if (SDLButtonState & SDL_BUTTON(3))
	{
		Button |= MIDDLE;
	}
	if (SDLButtonState & SDL_BUTTON(4))
	{
		Button |= WHEELUP;
	}
	if (SDLButtonState & SDL_BUTTON(5))
	{
		Button |= WHEELDOWN;
	}

	return Button;
}


}


